package com.controller;

import com.domain.Student;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.service.StudentService;
import com.sun.deploy.net.HttpResponse;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@org.springframework.stereotype.Controller
public class Controller {
    @Autowired
    private StudentService studentService;
    @RequestMapping("/findAll")
    public String findAll(@RequestParam(defaultValue = "1")int page,@RequestParam(defaultValue = "4")int size, Model model){
        PageHelper.startPage(page,size);
        List<Student> all = studentService.findAll();
        PageInfo<Student> pageInfo = new PageInfo<>(all);
        model.addAttribute("list",all);
        model.addAttribute("ps",pageInfo);
        return "index";
    }
    @RequestMapping("insert")
    public String insert(Student student){
        studentService.insert(student);
        return "redirect:findAll";
    }
    @RequestMapping("/delete")
    public String delete(Integer id){
        studentService.delete(id);
        return "redirect:findAll";
    }
    @RequestMapping("/update")
    public String update(Student student){
        studentService.update(student);
        return "redirect:findAll";
    }
}
